import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;

import java.util.Objects;

/**
 * <p>
 * ${table.comment} Mapper 接口
 * </p>
 *
 * @author ${author}
 * @since ${date?date}
 */
public interface ${table.mapperName} extends BaseMapper<${entity}>{
    @SuppressWarnings("unchecked")
    default IPage<${entity}> getList(${entity}Req req) {
        LambdaQueryWrapper<${entity}> wrapper = new LambdaQueryWrapper<>();
        <#list table.fields as field>
        <#if field.propertyName == "status">
        wrapper.eq(Objects.nonNull(req.getStatus()), ${entity}::getStatus, req.getStatus());
        </#if>
        </#list>
        <#list table.fields as field>
        <#if field.propertyName == "sort">
        wrapper.orderByAsc(${entity}::getSort);
        </#if>
        </#list>
        wrapper.orderByAsc(${entity}::getId);
        return selectPage(MPPageUtils.buildPage(req), wrapper);
    }

<#list table.fields as field>
    <#if field.propertyName == "sort">
    default Integer updateSort(${entity}Req req) {
        LambdaUpdateWrapper<${entity}> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(${entity}::getId, req.getId())
                .set(Objects.nonNull(req.getSort()), ${entity}::getSort, req.getSort());
        return update(null, wrapper);
    }
    </#if>
    <#if field.propertyName == "status">
    default Integer updateStatus(${entity}Req req) {
        LambdaUpdateWrapper<${entity}> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(${entity}::getId, req.getId())
                .set(Objects.nonNull(req.getStatus()), ${entity}::getStatus, req.getStatus());
        return update(null, wrapper);
    }
    </#if>
</#list>
}
